package com.rover.service.system;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.common.SessionInfo;
import com.common.SpringContextHolder;
import com.common.SysConfigData;
import com.utils.DateUtil;

/**
 * 用户管理类.
 * 
 */
@Service
@Transactional
public class CommonService {

	public Map<String, Object> getApplicationInfos() {
		SysConfigData manager = (SysConfigData) SpringContextHolder
				.getBean("sysConfigData");

		Map<String, Object> alls = new HashMap<String, Object>();

		alls.put("buildId", manager.getBuildId());
		alls.put("version", manager.getVersion());
		alls.put("productName", manager.getProductName());
		alls.put("vendor", manager.getVendor());
		alls.put("copyright", "Copyright &copy; " + manager.getYear() + " - "
				+ StringUtils.substring(DateUtil.format(new Date()), 0, 4)
				+ " &nbsp;" + manager.getVendor());
		alls.put("website", manager.getWebsite());

		// 当前用户
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes()).getRequest();
		SessionInfo u = (SessionInfo) request.getSession().getAttribute(
				"SessionInfo");

		alls.put("userName", ((u == null) || (u.getUser() == null)) ? "" : u
				.getUser().getName());

		return alls;
	}

}
